package com.scuec.groupfive.controller;

import com.github.pagehelper.PageInfo;
import com.scuec.groupfive.entity.UserFeedback;
import com.scuec.groupfive.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedback")
@CrossOrigin
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;
    // http://localhost:8080/feedback/list
    @GetMapping("/list")
    public List<UserFeedback> getFeedbackList() {
        return feedbackService.getFeedbackList();
    }

    @GetMapping("/pages")
    public PageInfo<UserFeedback> getFeedbackPages(Integer pageNum, Integer pageSize) {
        return feedbackService.getFeedbackPages(pageNum, pageSize);
    }

    @PostMapping("/insert")
    public int insertFeedback(@RequestBody UserFeedback feedback) {
        return feedbackService.insertFeedback(feedback);
    }
    // http://localhost:8080/feedback/user/2
    @GetMapping("/user/{userId}")
    public List<UserFeedback> getFeedbackByUserId(@PathVariable String userId) {
        return feedbackService.getFeedbackByUserId(userId);
    }
}